/*
 * @Author: xiehangyun 
 * @Date: 2025-05-16 10:34:03 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-08-15 16:25:40
 */

import Api from "src/api/Api";
import { CouponItem } from "types/type";

export interface CouponListResponse {
    list: CouponItem[];
    total: number;
}

// 优惠券接口
class MyCouponsApi extends Api {

    constructor() {
        super()
    }

    //获取优惠券列表
    getCouponList(data: {
        expireTime?: string;
        pageNum?: number;
        pageSize?: number;
        state?: string; // 已使用/未使用
    }) {
        if (["已使用", "未使用", undefined].includes(data.state)) {
            delete data.expireTime;
        } else {
            data.state = "未使用";
            // delete data.state;
        }
        return this._get('/my/coupon/listCouponGetRecord', data);
    }

    //领取优惠券
    addCouponGetRecord(couponCode: string) {
        return this._get('/my/coupon/addCouponGetRecord', { couponCode });
    }

    // 删除优惠券
    del(couponGetRecordId: number) {
        return this._get(`/my/coupon/deleteExpireCoupon/${couponGetRecordId}`);
    }

    // 创建转赠令牌
    createToken(couponGetRecordId: number) {
        return this._from('/coupon/transfer/createToken', { couponGetRecordId });
    }

    // 接收转赠优惠券
    receiveToken(transferToken: string) {
        return this._from('/coupon/transfer/receive', { transferToken });
    }

    // 查看转赠信息
    transferInfo(transferToken: string) {
        return this._get('/coupon/transfer/info', { transferToken });
    }

    // 取消转赠
    cancelTransfer(couponGetRecordId: number) {
        return this._from('/coupon/transfer/cancel', { couponGetRecordId });
    }





}

const myCouponsApi = new MyCouponsApi();

export default myCouponsApi;